package com.amos.isearch.main;

import com.amos.isearch.common.parser.MarkdownParser;
import com.amos.isearch.common.parser.PdfParser;
import com.amos.isearch.common.util.FileUtils;
import lombok.extern.slf4j.Slf4j;

import java.io.File;

/**
 * DESCRIPTION: ParserMain
 *
 * @author <a href="mailto:daoyuan0626@gmail.com">amos.wang</a>
 * @date 2021/1/23
 */
@Slf4j
public class ParserMain {

    public static final String DATA_HOME = "DATA/";

    public static void main(String[] args) {
        String mdFileName = DATA_HOME + "LinuxReadme.md";
        String pdfFileName = DATA_HOME + "LinuxReadme.pdf";

        readMarkdown(mdFileName);
        readPdf(pdfFileName);
    }

    private static void readMarkdown(String filename) {
        File file = new File(filename);
        if (!file.exists()) {
            log.error("文件 [{}] 不存在", file.getPath());
            return;
        }

        // 读取文件文本内容
        String txtContent = FileUtils.getContent(file);
        // log.debug("文本内容：" + txtContent);

        String render = MarkdownParser.parseHtml(txtContent);
        log.debug("Markdown转成HTML：" + render);
    }

    private static void readPdf(String filename) {
        File file = new File(filename);
        if (!file.exists()) {
            log.error("文件 [{}] 不存在", file.getPath());
            return;
        }

        String pdfContent = PdfParser.getContent(file);
        log.debug("PDF内容：" + pdfContent);
    }

}
